package com.cassi.rabbitmq.turorials.linster;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * @author caasi
 * @since 2022-01-26 14:33:12
 */

@Component
public class TestDirect {
    
    @RabbitListener(
            containerFactory = "rabbitmq-container-factory-vip",
            bindings = @QueueBinding(
                    value = @Queue(value = "ziyan.huangdong",
                            durable = "true",autoDelete = "false", exclusive = "false"),
                    exchange = @Exchange(value = "ziyan.order", durable = "true", autoDelete = "false"),
                    key = "800024509"
            )
    )
    public void on509Message(@Payload String message, Channel channel,
                          @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {

        try {
            System.out.println("509接收到消息:"+message);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
//            try {
//                channel.basicAck(deliveryTag,true);
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
        }
    }

    @RabbitListener(
            containerFactory = "rabbitmq-container-factory-vip",
            bindings = @QueueBinding(
                    value = @Queue(value = "ziyan.huangdong",
                            durable = "true",autoDelete = "false", exclusive = "false"),
                    exchange = @Exchange(value = "ziyan.order", durable = "true", autoDelete = "false"),
                    key = "800024508"
            )
    )
    public void on508Message(@Payload String message, Channel channel,
                             @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) {

        try {
            System.out.println("508接收到消息:"+message);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
//            try {
//                channel.basicAck(deliveryTag,true);
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
        }
    }
    
}
